<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="user-form">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list">
                    <ul>
                        <li>
                            房间名称：<input type="text" name="name"/>
                        </li>
                        <li>
                            房间类型：
                            <select name="type" th:with="type=${@dict.getType('room_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="module:room:add">
                <i class="fa fa-plus"></i> 新增房间
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="module:room:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-edit disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="module:room:remove">
                <i class="fa fa-remove"></i> 删除
            </a>

            <a class="btn btn-primary" onclick="roomVip()" shiro:hasPermission="module:userDetailMoney:detailList">
                <i class="fa fa-plus"></i> 房间会员
            </a>

            <a class="btn btn-primary" onclick="onOffSendPacket(1)" shiro:hasPermission="module:userDetailMoney:detailList">
                <i class="fa fa-plus"></i> 开启发包
            </a>
            <a class="btn btn-primary" onclick="onOffSendPacket(2)" shiro:hasPermission="module:userDetailMoney:detailList">
                <i class="fa fa-plus"></i> 关闭发包
            </a>

        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('module:room:edit')}]];
    var removeFlag = [[${@permission.hasPermi('module:room:remove')}]];
    var room_type = [[${@dict.getType('room_type')}]];
    var personal = [[${@dict.getType('personal')}]];
    var punishType = [[${@dict.getType('punishType')}]];
    var prefix = ctx + "module/room";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "房间",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '房间id',
                    visible: false
                },

                {
                    field: 'name',
                    title: '房间名称'
                },
                {
                    field: 'roomNumber',
                    title: '房间号码'
                },

                {
                    field: 'type',
                    title: "房间类型",
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(room_type, value);
                    }
                },


                {
                    field: 'user.nickName',
                    title: "群主昵称",
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //房间会员
    function roomVip() {
        var id = "";
        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }

        var url = prefix + '/roomVip/' + id;
        createMenuItem(url, "房间会员");
    }

    function onOffSendPacket(type) {
        var url = prefix + '/onOffSendPacket';
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: {type:type},
            success: function(result) {
                if(result.code==0){
                    layer.msg("成功！", { icon: 1 });
                }else {
                    layer.msg("失败！",{ icon: 2});
                }
            }
        };
        $.ajax(config);
    }

</script>
</body>
</html>